package com.example.redissiondemo;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test {

    @Autowired
    RedissonClient redissonClient;

    @GetMapping("/simple")
    public String enviList() {
        RLock lock = redissonClient.getLock("lei");
        lock.lock();
        System.out.println(Thread.currentThread().getName() + "获得锁");
        lock.unlock();
//        try {
//            Thread.sleep(10);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } finally {
//            System.out.println(Thread.currentThread().getName() + "释放锁");
//            lock.unlock();
//        }
        return "simple";
    }

}
